import numpy as np


def generate_array():
    x = np.array([1.0, 2.0, 3.0])
    print(x)
    print(type(x))


def operate_array():
    x = np.array([1.0, 2.0, 3.0])
    y = np.array([2.0, 4.0, 6.0])
    print(x + y)
    print(x - y)
    print(x * y)
    print(x / y)


def dim_array():
    A = np.array([[1, 2], [3, 4]])
    print(A)
    print(A.shape)
    print(A.dtype)

    B = np.array([[3, 0], [0, 6]])
    print(A + B)
    print(A * B)


# 访问元素
def element_array():
    X = np.array([[51, 55], [14, 19], [0, 4]])
    print(X)
    # 下标访问
    print(X[0])
    print(X[0][1])
    # 遍历访问
    for row in X:
        print(row)
    # 数组访问
    X = X.flatten()
    print(X)
    print(X[np.array([0, 2, 4])])
    # 条件访问
    print(X > 15)
    print(X[X > 15])


if __name__ == '__main__':
    # generate_array()
    # operate_array()
    # dim_array()
    element_array()